package com.huida.app.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

/**
 * @Description: 认证和鉴权的服务配置
 * @Author: Wangzz
 * @Version: 1.0.0
 * @CreateDate: Created in 2021/10/30 22:47
 * @UpdateDate: [dateFormat:YYYY-MM-DD][modifier][description]
 */

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    /**
     * 客户端配置
     * @param clients
     * @throws Exception
     */
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("client_muyan") // 定义注册的客户端ID
                .secret("hello") // 注册的密码
                .authorizedGrantTypes("authorization_code") // 响应类型
                .redirectUris("https://www.yootk.com") // 返回的路径，如果没有配置则无法使用
                .scopes("webapp");  // 授权范围
        /*
        * 4中授权类型
        *    1. 授权码(authorization_code)
        *    2. 隐藏式(implicit)
        *    3. 密码式(password)
        *    4. 客户端凭证(client credentials)
        * */
    }
}

//admin:hello@localhost/oauth/authorize?client_id=client_muyan&response_type=code&redirect_uri=https://www.yootk.com